*===============================================================================
*
*					WORKER BELIEFS ABOUT OUTSIDE OPTIONS
*		(c)	Simon Jaeger, Christopher Roth, Nina Roussille, Benjamin Schoefer
*							  2023 December 5
*						   	   	 Local Data 
*
*===============================================================================


********************************************************************************
*								Table II										   *
********************************************************************************
						
use "$temp/experiment1.dta", clear		

gen bias_treated = personalinfo*bias_belief_pct_w2

preserve

sum bias_belief_pct_w2
scalar mean = r(mean)
reg bias_belief_post_pct_w2 bias_belief_pct_w2 personalinfo bias_treated, r
estimates store bias0
estadd scalar mean

sum posttreatment_wagechange_pct_w2 if personalinfo==0
scalar mean = r(mean)
reg posttreatment_wagechange_pct_w2 bias_belief_pct_w2 personalinfo bias_treated, r
estimates store bias1
estadd scalar mean

sum quitelasticity_1_11 
scalar mean = r(mean)
reg quitelasticity_1_11 bias_belief_pct_w2 personalinfo bias_treated, r
estimates store bias3
estadd scalar mean

sum job_search_11 
scalar mean = r(mean)
reg job_search_11 bias_belief_pct_w2 personalinfo bias_treated, r
estimates store bias4
estadd scalar mean

sum bargaining_1_11 
scalar mean = r(mean)
reg bargaining_1_11 bias_belief_pct_w2 personalinfo bias_treated, r
estimates store bias5
estadd scalar mean

sum bargaining_2_1 
scalar mean = r(mean)
reg bargaining_2_1 bias_belief_pct_w2 personalinfo bias_treated, r
estimates store bias6
estadd scalar mean

sum bargaining_2_2 
scalar mean = r(mean)
reg bargaining_2_2 bias_belief_pct_w2 personalinfo bias_treated, r
estimates store bias7
estadd scalar mean

sum r_wage_employee_w2 
scalar mean = r(mean)	
reg r_wage_employee_w2 bias_belief_pct_w2 personalinfo bias_treated, r
estimates store bias8
estadd scalar mean

restore

esttab bias0 bias1 bias3 bias4 bias5 bias6 bias7 bias8 ///
	using "$tab/TableII.tex" , replace  ///
	starlevels(* 0.1  ** 0.05 *** 0.01)  ///
	cells("b(fmt(3) star)" se(par(( ))fmt(3)))  ///
	nodep noobs legend frag label ///
	varlabels( bias_treated "\textbf{Treated $\times$ Pre-Treat Estimation Error}" ///
	personalinfo "\textbf{Treated}" ///
	bias_belief_pct_w2 "\textbf{Pre-Treat Estimation Error}" ///
	_cons "\textbf{Constant}") ///
	keep(bias_treated personalinfo bias_belief_pct_w2 _cons) ///
	order(bias_treated personalinfo bias_belief_pct_w2 _cons) ///
	nomtitles  mlabels("Post-Treat" "Belief About" "Intended" "Intended" "Intended" "Intended Neg" "Intended Neg" ///
	"Reservation \\ & Estimation Error & Outside Option & Quit & Search & Negotiation & Magnitude & Magnitude & Wage Cut \\ & & (Wage Change) & Probability & Probability & Probability & (No Neg = 0) & (No Neg = Msg) & ") ///
	collabels(none)


	
eststo clear		
	
preserve

gen y=1

reg y y, nocons
estimates store bias0
sum bias_belief_pct_w2
scalar mean = r(mean)
estadd scalar mean
estadd scalar num = e(N)

reg y y, nocons
estimates store bias1
sum posttreatment_wagechange_pct_w2 if personalinfo==0
scalar mean = r(mean)
estadd scalar mean
estadd scalar num = e(N)

sum quitelasticity_1_11 if personalinfo==0
scalar mean = r(mean)
ivregress 2sls quitelasticity_1_11 bias_belief_pct_w2 (posttreatment_wagechange_pct_w2 = personalinfo bias_treated)
estimates store bias3
estadd scalar mean
estat firststage
mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 
estadd scalar num = e(N)
local se_bias3 `: di %5.3fc _se[posttreatment_wagechange_pct_w2]'

sum job_search_11 if personalinfo==0
scalar mean = r(mean)
ivregress 2sls job_search_11 bias_belief_pct_w2 (posttreatment_wagechange_pct_w2 = personalinfo bias_treated)
estimates store bias4
estadd scalar mean
estat firststage
mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 
estadd scalar num = e(N)
local se_bias4 `: di %5.3fc _se[posttreatment_wagechange_pct_w2]'

sum bargaining_1_11 if personalinfo==0
scalar mean = r(mean)
ivregress 2sls bargaining_1_11 bias_belief_pct_w2 (posttreatment_wagechange_pct_w2 = personalinfo bias_treated)
estimates store bias5
estadd scalar mean
estat firststage
mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 
estadd scalar num = e(N)
local se_bias5 `: di %5.3fc _se[posttreatment_wagechange_pct_w2]'

sum bargaining_2_1 if personalinfo==0
scalar mean = r(mean)
ivregress 2sls bargaining_2_1 bias_belief_pct_w2 (posttreatment_wagechange_pct_w2 = personalinfo bias_treated)
estimates store bias6
estadd scalar mean
estat firststage
mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 
estadd scalar num = e(N)
local se_bias6 `: di %5.3fc _se[posttreatment_wagechange_pct_w2]'

sum bargaining_2_2 if personalinfo==0
scalar mean = r(mean)
ivregress 2sls bargaining_2_2 bias_belief_pct_w2 (posttreatment_wagechange_pct_w2 = personalinfo bias_treated)
estimates store bias7
estadd scalar mean
estat firststage
mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 
estadd scalar num = e(N)
local se_bias7 `: di %5.3fc _se[posttreatment_wagechange_pct_w2]'

sum r_wage_employee_w2 if personalinfo==0
scalar mean = r(mean)
ivregress 2sls r_wage_employee_w2 bias_belief_pct_w2 (posttreatment_wagechange_pct_w2 = personalinfo bias_treated)
estimates store bias8
estadd scalar mean
estat firststage
mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4] 
estadd scalar num = e(N)
local se_bias8 `: di %5.3fc _se[posttreatment_wagechange_pct_w2]'

restore

esttab bias0 bias1 bias3 bias4 bias5 bias6 bias7 bias8 ///
	using "$tab/TableII.tex" , append frag ///
	starlevels(* 0.1  ** 0.05 *** 0.01) cells("b(fmt(3) star)" se(par(( ))fmt(3)))  ///
	nodep legend label collabels(none) ///
	varlabels( posttreatment_wagechange_pct_w2 "\textbf{IV: Endogenous Variable:}" ///
	_cons "\textbf{Constant}") ///
	keep(posttreatment_wagechange_pct_w2 _cons) ///
	order(posttreatment_wagechange_pct_w2 _cons) ///
	mtitles(none) mlabels(none) nonumbers scalars(fs) /// 
	stats(mean fs  num, fm(%05.3f 3 %8.0fc) ///
	labels("\textbf{Control Group Mean}" "\textbf{First-Stage F-Stat}" "$ N $")) ///
	substitute("&       0.000   &       0.000   &       0.000   &" "&&&&" "(.)" " " "                    &               &               &     (`se_bias3')   &     (`se_bias4')   &     (`se_bias5')   &     (`se_bias6')   &     (`se_bias7')   &     (`se_bias8')   \\" "\textbf{Belief About Outside Option (Wage Change)} &               &               &     (`se_bias3')   &     (`se_bias4')   &     (`se_bias5')   &     (`se_bias6')   &     (`se_bias7')   &     (`se_bias8')   \\")	// this last substitution is to add the line "Belief About Outside Option (Wage Change)" on the line of the standard errors

